package bookService;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import pojo.Book;
import util.DBUtil;
import dao.impl.BookDaoImpl;

public class LoadBooksFromFile {
	public static void main(String[] args) {
		List<Book> list = new ArrayList<Book>();
		Connection con = DBUtil.createConnection();
		BookDaoImpl impl = new BookDaoImpl();
		//读入文件
		ObjectInputStream in = null;
		Book book1 = new Book();
		try {
			in = new ObjectInputStream(new FileInputStream("test.txt"));
			long start = System.currentTimeMillis();
			list = (List<Book>)in.readObject();
			System.out.println(list.size());
			int i = 0;
			for(Book t:list){
				impl.addBook(t);
//				System.out.println(i++);
			}
			long end = System.currentTimeMillis();
			System.out.println("time " + (end - start));
		} catch (Exception e) {
			e.printStackTrace();
		}
		finally{
			try {
				in.close();
				try {
					con.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}
